package com.teemor.common.datasource.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

/**
 * @Description:
 * @author zhoulk
 * @date: 2019/11/27
 */
@Configuration
public class EsConfig {

    @Value("${spring.elasticsearch.rest.uris}")
    private String es_url;

    @Bean
    RestHighLevelClient client() {

        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(es_url).withConnectTimeout(10000).withSocketTimeout(100000)
                .build();

        return RestClients.create(clientConfiguration).rest();
    }
}
